<?php
class View_Admin_GroupCategory extends View_Admin_Index_Template
{
    public $oTemp;
    public function displayGroupCategoryIndex($oModel)
    {
        $this->initTemplate($oModel);
        $this->oTemp->assign_file('tempMainContent', PATH_TEMPLATE_ADMIN .'html/groupcategory_index.html');
        $this->oTemp->assign('pageHeding', $oModel->aLanguage[MODULE_HEADING]['category']);
        
        $this->oTemp->assign('toobar_new', '?sMod=groupcategory&sAction=do_add_form');
        $this->oTemp->parse('main.toobar_new');
        $this->oTemp->assign('toobar_save',"formSubmit('frmUpdate')");
        $this->oTemp->parse('main.toobar_save');
    }
    
    public function displayGroupCategoryNew($oModel)
    {
    	$this->initTemplate($oModel);
        $this->oTemp->assign_file('tempMainContent', PATH_TEMPLATE_ADMIN .'html/groupcategory_new.html');
        $this->oTemp->assign('pageHeding', $oModel->aLanguage[MODULE_HEADING]['category']);
          $this->oTemp->assign_file('temp_group_js', PATH_TEMPLATE_ADMIN .'html/groupcategory_js.html');
        
        $this->oTemp->assign('group_status', 'checked');
        
        $this->oTemp->assign('toobar_save', 'check_form()');
        $this->oTemp->parse('main.toobar_save');
        $this->oTemp->assign('toobar_cancel', '?sMod=groupcategory');
        $this->oTemp->parse('main.toobar_cancel');
    }
    public function displayGroupCategoryEdit($oModel)
    {
    	$this->initTemplate($oModel);
        $this->oTemp->assign_file('tempMainContent', PATH_TEMPLATE_ADMIN .'html/groupcategory_edit.html');
        $this->oTemp->assign_file('temp_group_js', PATH_TEMPLATE_ADMIN .'html/groupcategory_js.html');
		$this->oTemp->assign('pageHeding', $oModel->aLanguage[MODULE_HEADING]['category']);
		
        
        $this->oTemp->assign('toobar_save', 'check_form()');
        $this->oTemp->parse('main.toobar_save');
        $this->oTemp->assign('toobar_cancel', '?sMod=groupcategory');
        $this->oTemp->parse('main.toobar_cancel');
    }
    
    public function displayListGroupCategory($oModel)
    {
    	$rs=$oModel->getListGroupCategory();
    	if(is_array($rs))
    	{
    		$i = 0;
    		foreach($rs as $row)
    		{
    			$i++;
                $row['no'] = $i;
                $row['css'] = "row" . ($i % 2);
                if($row['group_status']==1)
                {
                	$row['group_status']='checked';
                }
    			$this->oTemp->assign('rowCategory',$row);
    			$this->oTemp->parse('main.rowCategory');
    		}
    	}
    }
    
    public function displayInfoGroupCategory($oModel,$id)
    {
    	$rs=$oModel->getInfoGroupCategory($id);
    	if(is_array($rs))
    	{
    		if($rs['group_status']==1)
    		{
    			$rs['group_status']='checked';
    		}
    		$this->assignExtract($rs);
    	}
    	
    	$rs_child=$oModel->getListGroupChild($id);
    	if(is_array($rs_child))
		{
			foreach($rs_child as $row)
			{
				//$row['selected']='selected';
				$this->oTemp->assign('rowChild',$row);
    			$this->oTemp->parse('main.rowChild');
			}
		}    
	}
    
    public function ajax_display_list_search_category($oModel)
    {
    	$rs=$oModel->getListSearchCategory();
    	if(is_array($rs))
    	{
    		foreach($rs as $row)
    		{
    			$this->oTemp->assign('row_list_category',$row);
    			$this->oTemp->parse('main.div_list_category.row_list_category');
    		}
    		$this->oTemp->parse('main.div_list_category');
    	}
    	return $this->oTemp->text('main.div_list_category');
    }
    
    public function resultXML($oModel, $cCMD, $cResult)
    {
        $oJSON = new Services_JSON();
        echo $oJSON->encode(array('HEAD' => array('CMD' => $cCMD, 'DATA' => date('d/m/Y H:m:s'), ),
            'BODY' => array('RES' => $cResult)));
    }
    
    /**
     * 
     */
    /*************************************************************************************************
    CATEGORY CHOOSE
    *************************************************************************************************/
    public function ajax_displayListParentCategory($oModel)
    {

        $rs = $oModel->getListParentCategoryChoose();
        if (is_array($rs))
        {
            $num_row = 0;
            foreach ($rs as $row)
            {
                $rs_child = $oModel->getListChildOnly($row['product_category_id']);
                if (is_array($rs_child))
                {
                    //$row['parent_img'] = URL_TEMPLATE_ADMIN . "image/arrow.gif";
                    $row['parent_img']='blue';
                }
                else
                    //$row['parent_img'] =	URL_TEMPLATE_ADMIN . "image/blank.png";
                    $row['parent_img']='#999999';

                    
                $row['highlight'] = "";
                $row['row_id'] = 0;
                $row['num_row'] = "parent" . $num_row;
                
                $this->oTemp->assign('i',$num_row%2);
                $num_row++;
                
                $this->oTemp->assign('RowCat', $row);
                $this->oTemp->parse('main.ResultCat.RowCat');
            }
            $this->oTemp->assign('row_id', 0);
            $this->oTemp->parse('main.ResultCat');
        }
        return $this->oTemp->text('main.ResultCat');
    }

    public function ajax_displayListChildCateogry($oModel, $parent_id)
    {
        $rs = $oModel->getListChildCategoryChoose($parent_id);
        $current_level = $oModel->getData('current_level');
        $next_level = $current_level + 1;
        //$_SESSION['test_count']=$next_level;

        if (is_array($rs))
        {
        	$num_row=0;
            foreach ($rs as $row)
            {
                $rs_child = $oModel->getListChildCategoryChoose($row['product_category_id']);

               if (is_array($rs_child))
                {
                    //$row['parent_img'] = URL_TEMPLATE_ADMIN . "image/arrow.gif";
                    $row['parent_img']='blue';
                }
                else
                    //$row['parent_img'] =	URL_TEMPLATE_ADMIN . "image/blank.png";
                    $row['parent_img']='#999999';

                $row['num_row'] = $next_level."_child" . $num_row;
                $num_row++;

                $row['row_id'] = $next_level;
                
				$this->oTemp->assign('i',$num_row%2);
                $num_row++;
                
                $this->oTemp->assign('RowCat', $row);
                $this->oTemp->parse('main.ResultCat.RowCat');
            }
            $this->oTemp->assign('row_id', $next_level);
            $this->oTemp->parse('main.ResultCat');
        }
        $aResult[0]=$this->oTemp->text('main.ResultCat');
        $aResult[1]=$next_level;
        return $aResult;
    }
}
?>